import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_purchased_subscription_cancellation_info.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_purchased_subscription_info_cancellation_info.dart';
import 'package:backend.purchases/domain/helpers/api/google_play/create_api_google_play_purchased_subscription_cancellation_survey_result_from_internal_one.dart';

abstract class CreateApiGooglePlayPurchasedSubscriptionCancellationInfoFromInternalOne {
  ApiGooglePlayPurchasedSubscriptionCancellationInfo call({
    required GooglePlayPurchasedSubscriptionInfoCancellationInfo cancellationInfo,
  });
}

class CreateApiGooglePlayPurchasedSubscriptionCancellationInfoFromInternalOneImpl
    implements CreateApiGooglePlayPurchasedSubscriptionCancellationInfoFromInternalOne {
  const CreateApiGooglePlayPurchasedSubscriptionCancellationInfoFromInternalOneImpl({
    required CreateApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne
        createApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne,
  }) : _createApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne =
            createApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne;

  final CreateApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne
      _createApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne;

  @override
  ApiGooglePlayPurchasedSubscriptionCancellationInfo call({
    required GooglePlayPurchasedSubscriptionInfoCancellationInfo cancellationInfo,
  }) {
    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoUserCancellationInfo) {
      final surveyResult =
          _createApiGooglePlayPurchasedSubscriptionCancellationSurveyResultFromInternalOne(
        surveyResult: cancellationInfo.surveyResult,
      );

      return ApiGooglePlayPurchasedSubscriptionUserCancellationInfo(
        time: cancellationInfo.time,
        surveyResult: surveyResult,
      );
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoSystemCancellationInfo) {
      return const ApiGooglePlayPurchasedSubscriptionSystemCancellationInfo();
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoDeveloperCancellationInfo) {
      return const ApiGooglePlayPurchasedSubscriptionDeveloperCancellationInfo();
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoNewSubscriptionCancellationInfo) {
      return const ApiGooglePlayPurchasedSubscriptionNewSubscriptionCancellationInfo();
    }

    throw UnimplementedError();
  }
}
